<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
         trimDirectiveWhitespaces="true"%>
<%@ page import="com.myfoon.action.backing.system.CountryBean, com.myfoon.model.entity.CountryName"%>
<%@ page import="javax.ejb.EJB"%>
<%@ page import="com.myfoon.model.cacheable.EventCache, 
                 com.myfoon.model.cacheable.UserCache, 
                 com.myfoon.action.backing.system.UserBean,
                 com.myfoon.action.backing.system.EventBean,
                 com.myfoon.model.entity.result.EventOfFriend,
                 com.myfoon.helper.SessionHelper,
                 com.myfoon.model.entity.User"%>
<%@ page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%              
    Cookie cookies[] =  request.getCookies();
    
    String fu_tz = "0";       
    SessionHelper sessionHelper = new SessionHelper(request);
    Integer tzOffset = sessionHelper.getTimeZoneOffset();        
    
    EventBean eventBean = new EventBean();
    User user;    
    User me;    
    
    String requestedId = request.getParameter("id");
    me = (User)session.getAttribute("user");    
    
    if (requestedId == null) {        
        user = (User)session.getAttribute("user");
    }
    else {
        user = new User();
        user.setId(Long.valueOf(requestedId));
    }
    
    Object friends[] = new UserBean().findRandomFriends(user);
    Integer totalFriendCount = (Integer)friends[0];
    List<UserCache> friendList = (List<UserCache>)friends[1];
        
    request.setAttribute("totalFriendCount", totalFriendCount);
    request.setAttribute("friends", friendList);        
    
    List<EventOfFriend> myEvents = eventBean.getLastEvents(user, new Integer(tzOffset), false, 0, 15);    
    request.setAttribute("myEvents", myEvents);
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="/css/global.css"/>
    <link rel="stylesheet" type="text/css" href="/css/home.css"/>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/curve.js"></script>
    <script type="text/javascript" src="/js/json2.js"></script>
    <script type="text/javascript" src="/js/home3.js"></script>
    <script type="text/javascript">           
      $(function() {                        
          $('.toolbox').cornerz({radius: 4, background: "white"})          
          $('#side').cornerz({radius: 6, background: "white"})                              
          $('.searchbox').cornerz({radius: 4, background: "white", corners: "bl br"})
          $('.r2side').cornerz({radius: 4, background: "white"})        
        })      
    </script>
    <title>Profile</title>    
  </head>
  <body>
    <div id="content">
      <div id="top">                
        <div id="top_menu">
            <span><a href="/home.jsp">Home</a></span>
            <span class="separator">|</span>
            <span><a href="/profile.jsp">Profile</a></span>
            <span class="separator">|</span>
            <span><a href="/friends.jsp">Friends</a></span>                        
            <span class="separator">|</span>            
            <span><a href="/friends.jsp">My Wiki</a></span>                        
            <span class="separator">|</span>            
            <span><a href="/communities.jsp" class="menulink">My Communities</a></span>
        </div>
        <div class="top_menu_right">
            <select class="mf_input mf_lang">
                <option value="1">English</option>
            </select>
        </div>
        <div class="top_menu_right">            
            <span><a href="/settings.jsp">Settings</a></span>
            <span class="separator">|</span>
            <span><a href="/help.jsp">Help</a></span>
            <span class="separator">|</span>
            <span><a href="/logout.jsp">Logout</a></span>                                                    
        </div>        
      </div>                   
      <div id="main">
        <div id="side">
          <div id="p_img">
            <img src="/images/onur.jpg" width="120" height="108" border="0"/>
          </div>
          
          <div class="menubox">
              <ul>
                <li><%= user.getUserPi().getFullname() %></li>
              </ul>
          </div>
          <div class="toolbox2">
            <ul>
                  <li>Edit My Profile</li>
                  <li>Edit My CV</li>                  
            </ul>        
          </div>
           
          <div class="menubox">
            <h4>Applications</h4>             
            <ul>
               <li>                    
                    <img src="http://b.static.ak.fbcdn.net/images/icons/gift.gif?8:32236" 
                    height="16" width="15" border="0" style="vertical-align:middle;">
                    </img>
                    <a href="abc">Gifts</a>
               </li>                                 
               <li>                    
                    <img src="http://photos-d.ak.fbcdn.net/photos-ak-sf2p/v43/79/4771353211/app_2_4771353211_2396.gif" 
                    height="16" width="16" border="0" style="vertical-align:middle;">
                    </img>
                    <a href="abc">Speed Date</a>
               </li>            
               <li>                    
                    <img src="http://photos-f.ak.fbcdn.net/photos-ak-sf2p/v43/33/41467512021/app_2_41467512021_5386.gif" 
                    height="16" width="16" border="0" style="vertical-align:middle;">
                    </img>
                    <a href="abc">Seçim Anketi</a>
               </li>                                      
            </ul>
          </div>
        </div>         
        <div id="right">
          <div id="r1">
            <div id="messagebox" class="rd">
              <h3><%= user.getUserPi().getFullname() %></h3>       
              <span><%= user.getUserPi().getBirthdate() %></span>
            </div>
             
            <div id="recentpostsbox" class="rd">              
              <div>                
                <h3>My Shares               
                    <span id="ajax_load" class="ajax_load"></span>
                </h3>                                       
              </div>
               <div id="recentposts">
              <table width="100%" cellpadding="5" cellspacing="0" border="0"
                     class="rp">
                <c:forEach var="evf" items="${myEvents}">
                  <tr>
                    <td width="50px">
                      <img src="images/man.png"/>
                    </td>
                    <td>
                      <span class="event_info">
                        <c:out value="${evf.ownerFullname}"></c:out>
                        <span class="event_time">                           
                          <fmt:formatDate type="time" timeStyle="short"
                                          value="${evf.date}"/>
                        </span>
                      </span>
                      <div class="event_message">
                      <span>
                        <c:out value="${evf.message}"/>
                      </span>
                      </div>
                    </td>
                  </tr>
                </c:forEach>
              </table>
              </div>
            </div>
          </div>
           
          <div id="r2">
            <div class="searchbox">
                <input type="text" class="mf_input mf_search"/>
                <a class="search_button" href="javascript: void(0);" onclick="alert('search');"></a>     
                <div style="clear: both;"></div>
            </div>                    
            <div class="r2side">
                <h4>Friends (<c:out value="${totalFriendCount}"/>)</h4>    
                <div class="r2sidebox_first">
                <table border="0" cellpadding="0" cellspacing="0" width="100%" >                                    
                    <c:set var="row" value="0"/>
                    <c:forEach var="friend" items="${friends}">                              
                     <c:if test="${row % 4 == 0}">
                        <tr>
                     </c:if>                                        
                        <td width="40px" style="margin: 0; padding: 0;">
                            <c:url var="url" value="/profile.jsp">
                                <c:param name="id" value="${friend.id}"/>
                            </c:url> 
                            <a href="${url}" class="profile_link">
                            <img title="${friend.fullname}" src="${ friend.photoSmall }" width="40px" height="40px" border="0"/>                            
                            </a>
                        </td>           
                        <c:set var="row" value="${row+1}"/>                
                    <c:if test="${row % 4 == 0}">                        
                        </tr>
                        <c:set var="row" value="0"/>
                    </c:if>                                  
                    </c:forEach>                                                                
                </table>                
                </div>
                <div style="text-align: right;">
                    <a class="applink" href="javascript: void(0);" style="font-weight: normal; color: #7C7C7C;"/>See All</a>
                </div>
            </div>
            
            <div class="r2side">
                <h4>Communities</h4>
            </div>
          </div>
        </div>
      </div>       
      <div id="bottom">
        <div class="bottom2">
        <ul class="about">
            <li class="first"><fmt:message key="global.myfoon"/></li>
            <li><a href="/advertise"><fmt:message key="global.advertise"/></a></li>
            <li><a href="/advertise">Developers</a></li>
            <li><a href="/advertise">Careers</a></li>
            <li><a href="/advertise">Privacy Policy</a></li>
            <li><a href="/advertise">Terms of Service</a></li>
            <li><a href="/advertise">Send Feedback</a></li>
            <li><a href="/advertise"><fmt:message key="global.help"/></a></li>    
        </ul>
        </div>
      </div>
    </div>
  </body>
</html>